1,832,479 (+ 9160)
58,795 (+ 93)
12,586,342 (+ 36858)
117,004
1,656,680 (96.6%)
If you have any comments, suggestions or ideas, please feel free to contact us: ginalamp@sun.ac.za or 22098038@sun.ac.za
Explain overall code here
---
title: "Final-ish Project Graphs"
author: "Johanna Engelhard and Gina Lamprecht"
output:
flexdashboard::flex_dashboard:
orientation: rows
source_code: embed
vertical_layout: scroll
html_document:
df_print: paged
---
# COVID-19 Dashboard
```{r import libraries}
library(tidyverse)
library(lubridate) # dates
library(chron) # reverse date plot
library(formattable) # round numbers
library(ggplot2)
library(scales) # add commas to axis
library(RcppRoll) # rolling average
library(flexdashboard) # html dashboard formatting
```
```{r}
custom_theme <- function () {
theme_minimal(base_size=12, base_family="Avenir") %+replace%
theme(
panel.background = element_blank(),
panel.grid.minor = element_blank(),
legend.position="none", # no legend
plot.title = element_text(size = 10, hjust = 0)
)
}
```
```{r set colours}
maroon <- "#60223b"
mustard <- "#F1B434"
darkgrey <- "#333333"
lightgrey <- "#8c979a"
black <- "#000000"
engineering_yellow <- "#eaaa00"
arts_orange <- "#FF8F1C"
military_salmon <- "#e56a54"
science_red <- "#cb333b"
law_winered <- "#9e2629"
theology_purple <- "#84329B"
education_darkblue <- "#326295"
ems_lightblue <- "#2dccd3"
agri_green <- "#509e2f"
med_bluegreen <- "#006163"
```
```{r set data width}
data_width_standard <- 400
```
```{r read data}
# general (cumulative) information regarding tests, deaths, and recoveries. Complete timeline.
tests_deaths_recoveries_data <- read.csv("data/covid19za_timeline_testing.csv")
# total (cumulative) number of confirmed cases by province
provincial_total_confirmed <- read.csv("data/covid19za_provincial_cumulative_timeline_confirmed.csv")
# provincial deaths, and recoveries
provincial_recoveries_data<- read.csv("data/covid19za_provincial_cumulative_timeline_recoveries.csv")
# lockdown levels
national_lockdown<- read.csv("data/national_lockdown_govza.csv")
# death data
death_data <- read.csv("data/covid19za_provincial_cumulative_timeline_deaths.csv")
# owid SA extracted (big) data
owid_sa_data <- read.csv("data/owid-covid-data_SouthAfricaExtracted_big.csv")
```
```{r value box death and recovered}
# total deaths
total_deaths <- max(tests_deaths_recoveries_data$deaths, na.rm = TRUE)
# get last day's number of deaths increase
last_death_cols <- tail(tests_deaths_recoveries_data$deaths, n=2)
death_day_update <- last_death_cols[2] - last_death_cols[1]
# total recovered
total_recovered <- max(tests_deaths_recoveries_data$recovered, na.rm = TRUE)
# percentage recovered
percentage_recovered <- total_recovered / (total_recovered + total_deaths) * 100
```
```{r value box active and confirmed cases}
# total confirmed cases
total_confirmed <- max(provincial_total_confirmed$total, na.rm = TRUE)
# get last day's number of confirmed increase
last_confirmed_cols <- tail(provincial_total_confirmed$total, n=2)
confirmed_day_update <- last_confirmed_cols[2] - last_confirmed_cols[1]
# active cases = confirmed cases - recoveries - deaths
total_active <- total_confirmed - total_recovered - total_deaths
```
```{r value box tests}
# get number of tests
total_tests <- max(tests_deaths_recoveries_data$cumulative_tests, na.rm = TRUE)
# get last day's number of tests increase
last_tests_cols <- tail(tests_deaths_recoveries_data$cumulative_tests, n=2)
test_day_update <- last_tests_cols[2] - last_tests_cols[1]
```
```{r bubble new tests and cases}
bubble_data <- owid_sa_data %>%
select(date, new_cases, new_tests) %>%
filter(!is.na(new_cases)) %>%
filter(!is.na(new_tests)) %>%
mutate(date = as.Date(date))
```
```{r last 20 days new cases}
# Get total confirmed cases per date
confirmed <- owid_sa_data %>%
filter(!is.na(new_cases)) %>%
select(date, new_cases) %>%
mutate(date = as.Date(date)) %>%
filter(date > as.Date("2021-06-01"))
confirmed <- confirmed %>% map_df(rev)
```
Row {data-width=400}
-----------------------------------------------------------------------
### confirmed cases {.value-box}
```{r plot confirmed cases box}
valueBox(
value = paste(format(total_confirmed, big.mark = ","), " (+ ", confirmed_day_update,")", sep = ""),
caption = "CONFIRMED CASES",
icon = "fas fa-user-md",
color = maroon
)
```
### total deaths {.value-box}
```{r plot total deaths box}
valueBox(
value = paste(format(total_deaths, big.mark = ","), " (+ ", death_day_update,")", sep = ""),
caption = "DEATHS",
icon = "fas fa-user-md",
color = science_red
)
```
### total tests {.value-box}
```{r plot total tests box}
valueBox(
value = paste(format(total_tests, big.mark = ","), " (+ ", test_day_update,")", sep = ""),
caption = "TESTS",
icon = "fas fa-user-md",
color = med_bluegreen
)
```
Row {data-width=400}
-------------------------------------
### active cases {.value-box}
```{r plot active cases box}
valueBox(
value = paste(format(total_active, big.mark = ","), "", sep = " "),
caption = "ACTIVE CASES",
icon = "fas fa-user-md",
color = mustard
)
```
### recovered {.value-box}
```{r plot recovered box}
valueBox(
value = paste(format(total_recovered, big.mark = ","), " (", round(percentage_recovered, 1),"%)", sep = ""),
caption = "RECOVERED",
icon = "fas fa-user-md",
color = agri_green
)
```
Row {data-width=400}
-------------------------------------
### **Daily vaccinations**
### **Total vaccinations**
Row {data-width=data_width_standard}
-------------------------------------
### **Daily confirmed cases**
Row {data-width=data_width_standard}
-------------------------------------
### **Active case total by day**
### **Daily deaths**
Row {data-width=data_width_standard}
-------------------------------------
### **Daily case trends**
Row {data-width=data_width_standard}
-------------------------------------
### **Cases vs Active Cases**
### **Total Deaths**
### **Doubling Rates**
Row {data-width=data_width_standard}
-------------------------------------
### **Deaths by Province**
### **Deaths by Province (per 100k)**
### **Prov Infections per 100,000 Population**
Row {data-width=data_width_standard}
-------------------------------------
### **Confirmed and Active Cases by Province**
Row {data-width=data_width_standard}
-------------------------------------
### **Average daily tests per week**
### **Average daily positives per week**
### **No of tests per positive case (weekly)**
Row {data-width=data_width_standard}
-------------------------------------
### **Daily tests and positive cases**
```{r fig.width = 8}
# TODO: Add number of test labels on specific dates
# TODO: Y axis labeling (cap at 60k, but allow graph to continue upward)
ggplot(bubble_data, aes(x=date, y=new_tests, size = new_cases)) +
geom_point(alpha=0.5, color=theology_purple) +
scale_size(range = c(.1, 10)) +
scale_x_date(date_breaks = "1 month", date_labels = "%d/%m") +
scale_y_continuous(label=comma) +
labs(title = "Number of tests per day",
x = NULL,
y = NULL,
caption = element_text("Updated: June 2021")) +
custom_theme()
```
Row {data-width=data_width_standard}
-------------------------------------
### **Confirmed infections (last 20 days)**
```{r fig.width=15}
# TODO: not plotting right (even when flipping the dates here - the date labels are wrong)
ggplot(confirmed, aes(x=rev(date), y=new_cases, fill=military_salmon)) +
geom_col(position="dodge") +
geom_text(aes(label = new_cases), position = position_dodge(0.9), hjust=-0.1) + # add labels
labs(caption = "Updated: June 2021",
x = NULL,
y = NULL) +
scale_x_date(date_breaks = "1 day", date_labels = "%m-%d-%Y") +
scale_y_continuous(labels = NULL, breaks = NULL) + # remove unnecessary ticks
coord_flip() +
custom_theme()
```
Row {data-width=data_width_standard}
-------------------------------------
### **Positivity Rate: Number of Tests vs Positive Cases (%)**
Row {data-width=data_width_standard}
-------------------------------------
### **National Hospital Admissions**
### **Public vs. Private Tests**
Row {data-width=data_width_standard}
-------------------------------------
### **Current Rt estimates for South Africa**
Row {data-width=data_width_standard}
-------------------------------------
### **Excess Deaths (South Africa)**
### **Excess Deaths (Provinces)**
### **Excess Deaths (Metros)**
Row {data-width=data_width_standard}
-------------------------------------
### **New daily confirmed Covid-19 cases: 7-day average**
Row {data-width=200}
-------------------------------------
If you have any comments, suggestions or ideas, please feel free to contact us: ginalamp@sun.ac.za or 22098038@sun.ac.za
# Project Writeup
Explain overall code here
# Background Research
* Excess deaths
* Doubling rate
# Sources
* TODO